--[[
通用面板功能
]]

--[[
这套协议、面板（包括CommonActivityPanelCfg），宗旨是尽可能减少客户端面板与具体某个活动、副本的配置关联
客户端不需要关心具体某个活动的配置
]]
------------------------------活动、副本的右侧通用面板----begin----------------------------------
--[通用活动/副本面板]初始化
function OpenActivityRightPanel( sysarg, panelType, activityId, panelInfo )
	local npack = DataPack.allocPacket(sysarg, enDefaultEntitySystemID, sCommonRightPanelOpen)
	if not npack then
		return
	end

	if not panelInfo.contAwards then
		panelInfo.contAwards = {}
	end

	DataPack.writeByte(npack, panelType)			              --类型1： 副本   类型2:活动
	DataPack.writeShort(npack, activityId)			              --活动ID，客户端可以根据不同的活动调整布局显示
	DataPack.writeShort(npack, panelInfo.subActivityId or 0)	
	DataPack.writeByte( npack, panelInfo.sts )		              --状态,1-进行中，2-已结束

	DataPack.writeByte(npack, panelInfo.showStyle or 1)		--显示风格，1-缺省风格，2-不显示面板，只显示门状的退出按钮和倒计时，
																--3-显示面板和门状的退出按钮	
	DataPack.writeUInt(npack, panelInfo.param or 0)			--参数

	DataPack.writeString(npack, panelInfo.title or "")	          --""则客户端不需要显示
	--print("OpenActivityRightPanel, activityId="..activityId..", title="..panelInfo.title)

	--布局1-活动/副本的剩余时间
	DataPack.writeString(npack, panelInfo.timeTitle)
	DataPack.writeUInt(npack,  panelInfo.restTime)			--剩余时间
	--print("OpenActivityRightPanel, restTime="..panelInfo.restTime)

	--布局2-活动/副本的内容
	DataPack.writeString( npack, panelInfo.contentTitle or "" )    --""则客户端不需要显示
	--print("OpenActivityRightPanel, contentTitle="..panelInfo.contentTitle)
	DataPack.writeByte( npack, table.getn(panelInfo.contents or {}) or 0 )			--内容数量
	for idx, content in pairs( panelInfo.contents or {} ) do
		DataPack.writeByte(npack, idx)								--第N条内容
		DataPack.writeString(npack, content)
		--print("OpenActivityRightPanel, idx="..idx..", content="..content)
		--[[
		local contAwards = panelInfo.contAwards[idx] or {}
		local contAwardNum = table.getn( contAwards ) or 0
		DataPack.writeByte( npack, contAwardNum )
		for i, contAward in ipairs( contAwards or {} ) do
			DataPack.writeByte(npack, contAward.type)
			DataPack.writeInt(npack,  contAward.id)
			DataPack.writeUInt(npack, contAward.count)
			DataPack.writeByte(npack, contAward.quality)
			DataPack.writeByte(npack, contAward.bind)
			--print("OpenActivityRightPanel, type="..contAward.type..", id="..contAward.id..", count="..contAward.count)
		end
		]]
	end

	--布局3-活动/副本的奖励
	DataPack.writeString(npack, panelInfo.awardTitle or "")
	DataPack.writeByte(npack, table.getn(panelInfo.awards or {}) or 0 )			--内容数量
	--print("OpenActivityRightPanel, awardTitle="..panelInfo.awardTitle..", #awardNum="..#panelInfo.awards)
	for i, award in ipairs( panelInfo.awards or {} ) do 			--内容
		DataPack.writeByte(npack, award.type)
		DataPack.writeInt(npack,  award.id)
		DataPack.writeUInt(npack, award.count)
		DataPack.writeByte(npack, award.quality)
		DataPack.writeByte(npack, award.bind)
		--print("OpenActivityRightPanel, type="..award.type..", id="..award.id..", count="..award.count)
	end

	--buttonId : 1-退出副本，2-单倍领奖，3-双倍领奖
	if not panelInfo.buttonParams then		--按钮参数
		panelInfo.buttonParams = {}
	end
	DataPack.writeByte(npack, table.getn(panelInfo.buttons or {}) or 0 )			--按钮数量
	for i, buttonId in ipairs( panelInfo.buttons or {} ) do
		DataPack.writeByte(npack, buttonId)
		local buttonParam = panelInfo.buttonParams[i] or 0
		DataPack.writeShort(npack, buttonParam )
		--print("OpenActivityRightPanel, buttonId="..buttonId..", buttonParam="..buttonParam)
	end

	--DataPack.writeString(npack, panelInfo.otherTimeTitle or "")			--额外时间title
	--DataPack.writeByte( npack, panelInfo.otherTimeType or 2 )    --额外时间类型 1递增 2递减
	--DataPack.writeUInt(npack,  panelInfo.otherRestTime or 0)			--剩余时间
	

	--[[
	if panelInfo.desc then
		DataPack.writeString(npack,  panelInfo.desc)		--活动描述
	else
		DataPack.writeString(npack,  "")
	end
	]]
	DataPack.flush(npack) 
end

--[通用活动/副本面板]改变内容
function ChangeActivityRightPanel( sysarg, panelInfo )
	local npack = DataPack.allocPacket(sysarg, enDefaultEntitySystemID, sCommonRightPanelChange)
	if not npack then
		return
	end

	if not panelInfo.contAwards then
		panelInfo.contAwards = {}
	end

	--print("ChangeActivityRightPanel, sts="..panelInfo.sts)
	--布局1-活动/副本的内容
	DataPack.writeByte( npack, panelInfo.sts )			    --状态
	DataPack.writeByte( npack,  GetElemsNum( panelInfo.contents ) )			--内容数量
	for idx, content in pairs( panelInfo.contents or {} ) do
		DataPack.writeByte(npack, idx)
		DataPack.writeString(npack, content)
		--print("ChangeActivityRightPanel, idx="..idx..", content="..content)
		--[[
		local contAwards = panelInfo.contAwards[idx] or {}
		local contAwardNum = table.getn( contAwards ) or 0
		DataPack.writeByte( npack, contAwardNum )
		for i, contAward in ipairs( contAwards or {} ) do
			DataPack.writeByte(npack, contAward.type)
			DataPack.writeInt(npack,  contAward.id)
			DataPack.writeUInt(npack, contAward.count)
			DataPack.writeByte(npack, contAward.quality)
			DataPack.writeByte(npack, contAward.bind)
			--print("-->contAward, type="..contAward.type..", id="..contAward.id..", count="..contAward.count)
		end
		]]
	end

	--buttonId : 1-退出副本，2-单倍领奖，3-双倍领奖
	if not panelInfo.buttonParams then		--按钮参数
		panelInfo.buttonParams = {}
	end
	DataPack.writeByte(npack, table.getn(panelInfo.buttons or {}) or 0 )			--按钮数量
	for i, buttonId in ipairs( panelInfo.buttons or {} ) do
		DataPack.writeByte(npack, buttonId)
		local buttonParam = panelInfo.buttonParams[i] or 0
		DataPack.writeShort(npack, buttonParam )
		--print("ChangeActivityRightPanel, buttonId="..buttonId..", buttonParam="..buttonParam)
	end
	
	--print("ChangeActivityRightPanel, num="..num)
	--布局3-活动/副本的剩余时间
	--DataPack.writeUInt(npack,  panelInfo.restTime)
	DataPack.flush(npack) 
end

--[通用活动/副本面板]关闭面板
function CloseActivityRightPanel( sysarg )
	--print("CloseActivityRightPanel...")
	local npack = DataPack.allocPacket(sysarg, enDefaultEntitySystemID, sCommonRightPanelClose)
	if npack then
		DataPack.flush(npack)
	end
end

--[通用活动/副本面板]通关面板
function PassActivityRightPanel( sysarg, panelType, activityId, panelInfo )
	--print("PassActivityRightPanel, activityId="..activityId..", sts="..panelInfo.sts)
	local npack = DataPack.allocPacket(sysarg, enDefaultEntitySystemID, sCommonRightPanelPass)
	if not npack then
		return
	end

	if not panelInfo.awards then
		panelInfo.awards = {}
	end

	DataPack.writeByte(npack,  panelType)			                --类型1： 副本   类型2:活动
	DataPack.writeShort(npack, activityId)			                --活动ID，客户端可以根据不同的活动调整布局显示
	DataPack.writeShort(npack, panelInfo.subActivityId or 0)		--子活动ID，
	DataPack.writeUInt( npack, panelInfo.param1 or 0 )				--参数
	DataPack.writeByte( npack, panelInfo.sts )	 					--通关状态，0-通关失败，1-通关成功
	if panelInfo.sts == 0 then
		DataPack.flush(npack)
		return
	end

	DataPack.writeUInt( npack, panelInfo.passTime or 0 )	 		--通关时间
	DataPack.writeShort(npack, panelInfo.star or 0)					--通关星级
	--print( " PassActivityRightPanel, star="..panelInfo.star )

	DataPack.writeByte(npack, table.getn(panelInfo.awards or {}) or 0 )			--内容数量
	--print("PassActivityRightPanel, awardNum="..#panelInfo.awards)
	for i, award in ipairs( panelInfo.awards or {} ) do 			--内容
		DataPack.writeByte(npack, award.type)
		DataPack.writeInt(npack,  award.id)
		DataPack.writeUInt(npack, award.count)
		DataPack.writeByte(npack, award.quality or 0)
		DataPack.writeByte(npack, award.bind or 0)
		--print("PassActivityRightPanel, type="..award.type..", id="..award.id..", count="..award.count)
	end
	DataPack.flush(npack) 
end

--[通用活动/副本面板]同步活动时间
function SynTimeActivityRightPanel( sysarg, activityId, restTime )
	--print("SynTimeActivityRightPanel, restTime="..restTime)
	local npack = DataPack.allocPacket(sysarg, enDefaultEntitySystemID, sCommonRightPanelSynTime)
	if npack then
		DataPack.writeShort(npack, activityId)
		DataPack.writeUInt(npack,  restTime)			--剩余时间
		DataPack.flush(npack) 
	end
end

------------------------------活动、副本的右侧通用面板----end------------------------------------

------------------------------倒计时面板----begin----------------------------------
--[通用倒计时面板]初始化
function OpenCountDownPanel( sysarg, activityId, panelInfo )
	local npack = DataPack.allocPacket(sysarg, enDefaultEntitySystemID, sCommonCountDownPanelOpen)
	if not npack then
		return
	end

	DataPack.writeShort( npack, activityId )
	DataPack.writeString(npack, panelInfo.title or "")				--内容
	DataPack.writeUInt(npack, panelInfo.restTime or 0)				--活动剩余时间
	--print("OpenCountDownPanel, title="..panelInfo.title..", restTime="..panelInfo.restTime)

	DataPack.writeByte( npack,  GetElemsNum( panelInfo.content ) or 0 )			--内容数量
	for idx,info in ipairs( panelInfo.content or {} ) do 			                --连续的table
		DataPack.writeByte(npack, idx)
		DataPack.writeString(npack, info[1])				--内容
		DataPack.writeUInt(npack, info[2])			        --倒计时
		DataPack.writeUInt(npack, info[3] or 0 )			--目标ID
		--print("OpenCountDownPanel, idx="..idx..", desc="..info[1]..", lastTime="..info[2]..", param="..info[3])
	end
	DataPack.flush(npack)
end

--[通用倒计时面板]改变面板的内容
function ChangeCountDownPanel( sysarg, content )
	local npack = DataPack.allocPacket(sysarg, enDefaultEntitySystemID, sCommonCountDownPanelChange)
	if not npack then
		return
	end

	DataPack.writeByte(npack, 	content.idx)
	DataPack.writeString(npack, content.info[1])				    --内容
	DataPack.writeUInt(npack, 	content.info[2])			        --倒计时
	DataPack.writeUInt(npack, 	content.info[3] or 0 )			--目标ID
	--print("ChangeCountDownPanel, idx="..content.idx..", desc="..content.info[1]..", lastTime="..content.info[2]..", param="..content.info[3])
	DataPack.flush(npack) 
end

--[通用倒计时面板]关闭活动
function CloseCountDownPanel( sysarg )
	--print("CloseCountDownPanel...")
	local npack = DataPack.allocPacket(sysarg, enDefaultEntitySystemID, sCommonCountDownPanelClose)
	if npack then
		DataPack.flush(npack)
	end
end

--[通用倒计时面板]请求某个活动的数据
function SendCountDownPanel( sysarg, activityId )
	if activityId == enCountDownPanelActivity_MayaPalace then
		SendMayaPalaceCountDownPanel( sysarg )		--同步一次玛雅神殿面板数据
	end
end

------------------------------倒计时面板-----begin----------------------------------


------------------------------公告牌面板----begin----------------------------------
--[[
公告板类型：
	enBoardPanelStyle_Default			= 1,				//缺省。默认风格
	enBoardPanelStyle_ShortCut			= 2,				//快捷栏上
	enBoardPanelStyle_CountDown1		= 3,				//倒计时1（发送时间（秒），客户端收到后开始倒计时，到0时面板消失）
	enBoardPanelStyle_Right				= 4,				//正确，字符串前面有勾
	enBoardPanelStyle_Error				= 5,				//错误，字符串前面有叉
]]
--打开
function OpenBoardPanel( sysarg, boardStyle, content, param )
	--print("OpenBoardPanel, boardStyle="..boardStyle..", content="..content)
	if not boardStyle then
		return
	end

	local npack = DataPack.allocPacket(sysarg, enDefaultEntitySystemID, sCommonBoardOpen)
	if not npack then
		return
	end

	DataPack.writeByte( npack, boardStyle )			        --风格类型：1-默认
	DataPack.writeString(npack, content or "" )			    --内容
	DataPack.writeUInt(npack, param or 0)         			--参数
	DataPack.flush(npack)
end


--关闭面板
function CloseBoardPanel( sysarg )
	--print("CloseBoardPanel...")
	local npack = DataPack.allocPacket(sysarg, enDefaultEntitySystemID, sCommonBoardClose)
	if npack then
		DataPack.flush(npack)
	end
end

------------------------------公告牌面板+倒计时面板-----begin----------------------------------

--[[
初始化右侧面板
contStyle:内容风格
1：  击杀BOSS：xx/xx
	 击杀小怪：xx/xx
2：  击杀BOSS1名称：0/1
	 击杀BOSS2名称：0/1
	 击杀BOSS3名称：0/1
	 击杀小怪：xx/xx
3:	击杀怪物：xx/xx
4:  剩余时间
5:	总共怪物波数：xx
	当前怪物波数：xx
	下次刷出：xx分钟 或者 即将刷出
6：
	第一名玩家：%s
	第一名积分：%d
	我的积分：%d
	我的名次：%d
7:
总伤害:%d
攻击次数:%d
平均伤害:%d


9：排名(非来自于排行榜)

button--1：退出副本，2-单倍领奖，3-双倍领奖，4-查看排行榜，5-押镖寻路, 6-打开答题面板，7-放弃押镖，8-寻找活动NPC，
	9-排名(非来自于排行榜)、10-选择BOSS（具体客户端处理）
]]
function OpenCommonStylePanel( sysarg, activityType, activityId, subActivityId, title, bossConfig, contStyle, buttons, panelParams )
	--print("OpenCommonStylePanel, activityId="..activityId..", contStyle="..contStyle)
	local fubenPtr 		= Actor.getFubenPrt(sysarg)
	local restTime 		= 0
	if activityType == 1 then										--副本
		restTime = Fuben.getFbTime( fubenPtr )						--副本剩余时间
	else
		restTime = bossConfig.restTime or 0 						--场景剩余时间
	end
	
	local panelInfo 		= {}
	panelInfo.sts 			= 1  									--进行中
	panelInfo.subActivityId = subActivityId
	panelInfo.title 		= title									--title

	panelInfo.restTime	= restTime
	if panelInfo.restTime > 0 then
		panelInfo.timeTitle = Lang.ScriptTips.panelCont01				--剩余时间
	else
		panelInfo.timeTitle = ""				                        --不显示剩余时间
	end

	if contStyle ~= 4 then
		if activityType == 1 then
			panelInfo.contentTitle 	= Lang.ScriptTips.panelCont05  			--副本内容Title
		else
			panelInfo.contentTitle 	= Lang.ScriptTips.panelCont37 			--活动内容Title
		end
		panelInfo.contents 		= {}
	end

	local contIdx = 0
	----额外参数处理
	if panelParams then	
		for i, content in ipairs( panelParams.contents or {} ) do 		--部分特色显示内容
			contIdx = i
			panelInfo.contents[contIdx] = content
		end
	end

	local bossNumFunc = nil
	if contStyle == 1 then
		local fubenPtr 		= Actor.getFubenPrt(sysarg)
		local fubenHandle	= Fuben.getFubenHandle(fubenPtr)
		contIdx = contIdx + 1
		local allBoss, killBoss, allMon, killMon = GetCommonBossMonsterNum6( fubenHandle, bossConfig.monsters )
		panelInfo.contents[contIdx] = string.format( Lang.ScriptTips.panelCont08, killBoss, allBoss)
		if allMon > 0 then
			contIdx = contIdx + 1
			panelInfo.contents[contIdx] = string.format( Lang.ScriptTips.panelCont07, killMon, allMon)
		end
	elseif contStyle == 2 then
		local fubenPtr 		= Actor.getFubenPrt(sysarg)
		local fubenHandle	= Fuben.getFubenHandle(fubenPtr)
		local bossNumTable = GetCommonBossNum( fubenHandle, bossConfig.monsters )
		for bossId, bossNum in pairs( bossNumTable or {} ) do
			contIdx = contIdx + 1
			local bossName = MonsterNameDeleteNumber( bossId )
			panelInfo.contents[contIdx] = string.format( Lang.ScriptTips.panelCont13, bossName, bossNum[1], bossNum[2])
		end
	elseif contStyle == 3 then
		local fubenPtr 		= Actor.getFubenPrt(sysarg)
		local fubenHandle	= Fuben.getFubenHandle(fubenPtr)
		local allBoss, killBoss, allMon, killMon = GetCommonBossMonsterNum6( fubenHandle, bossConfig.monsters )
		panelInfo.contents[1] = string.format( Lang.ScriptTips.panelCont07, killBoss+killMon, allBoss+allMon)
	elseif contStyle == 4 then
		--无
	elseif contStyle == 5 then
			local curFreshTime = bossConfig.curFreshTime or 0
			local str = ""
			if curFreshTime <= 0 then
				str = Lang.ScriptTips.panelCont29
			else
				local now 			= System.getCurrMiniTime()
				local intervalTime 	= bossConfig.intervalTime or 0
				local nextFreshMin 	= ( intervalTime-(now-curFreshTime) )/60
				if nextFreshMin > 0 then
					str = string.format( Lang.ScriptTips.panelCont27, nextFreshMin )
				else
					str = Lang.ScriptTips.panelCont28
				end
			end

			local allBossIdx = bossConfig.allBossIdx or 0
			local curBossIdx = bossConfig.curBossIdx or 0
			panelInfo.contents[1] = string.format( Lang.ScriptTips.panelCont24, allBossIdx )
			panelInfo.contents[2] = string.format( Lang.ScriptTips.panelCont25, curBossIdx )
			panelInfo.contents[3] = string.format( Lang.ScriptTips.panelCont26, str )

			panelInfo.timeTitle = ""				--剩余时间
			panelInfo.restTime	= 0
	elseif contStyle == 6 then
		--[[
		panelCont16 = "我的积分:%d",
		panelCont19 = "我的排名:未上榜",
		panelCont20 = "我的排名:%d",
		panelCont31 = "第一名玩家:%s",
		panelCont32 = "第一名积分:%d",
		panelCont33 = "虚位以待",

		local actorName1 	= bossConfig.actorName1 or ""
		local actorPoint1 	= bossConfig.actorPoint1 or 0
		local myPoint 		= bossConfig.myPoint or ""
		local myRankIdx 	= bossConfig.myRankIdx or 0
		]]
		local actorId 	= Actor.getActorId( sysarg )
		local rankType 	= bossConfig.rankType or 0
		local actorName, actorPoint = GetCommonRankIdxNameAndValue( rankType, 1 )		--第一名
		--print("OpenCommonStylePanel, actorName="..actorName)
		local myIdx, myPoint = GetCommonRankActorIdxAndValue( rankType, actorId )		--本人
		if not actorName then
			actorName = Lang.ScriptTips.panelCont33
		end
		panelInfo.contents[1] = string.format( Lang.ScriptTips.panelCont31, actorName )
		panelInfo.contents[2] = string.format( Lang.ScriptTips.panelCont32, actorPoint )
		panelInfo.contents[3] = string.format( Lang.ScriptTips.panelCont16, myPoint )
		if myIdx > 0 then
			panelInfo.contents[4] = string.format( Lang.ScriptTips.panelCont20, myIdx )
		else
			panelInfo.contents[4] = Lang.ScriptTips.panelCont19
		end

		if not sts then
			sts = 1 			--进行中
		end
	elseif contStyle == 7 then
		--[[
		panelCont34 = "总伤害:%d",
		panelCont35 = "攻击次数:%d",
		panelCont36 = "平均伤害:%d",
		]]
		local allHurt 	= bossConfig.allHurt			--总伤害
		local attackNum = bossConfig.attackNum			--攻击次数
		local avgHurt 	= 0
		if attackNum > 0 then
			avgHurt = math.floor( allHurt/attackNum )		--平均攻击
		end
		panelInfo.contents[1] = string.format( Lang.ScriptTips.panelCont34, allHurt )
		panelInfo.contents[2] = string.format( Lang.ScriptTips.panelCont35, attackNum )
		panelInfo.contents[3] = string.format( Lang.ScriptTips.panelCont36, avgHurt )
		
		if not sts then
			sts = 1 			--进行中
		end
	elseif contStyle == 9 then			--排名(非来自于排行榜)
		local myRankIdx = bossConfig.myRankIdx
		panelInfo.contents[1] = string.format( Lang.ScriptTips.panelCont20, myRankIdx )
	end

	if bossConfig and bossConfig.awards then
		panelInfo.awardTitle 	= Lang.ScriptTips.panelCont06  			--副本奖励Title
		panelInfo.awards 		= bossConfig.awards						--副本奖励
	end

	if buttons then
		panelInfo.buttons  		= buttons or {}			--{1,2,3}		1-退出，2-（单倍）领奖，3-双倍领奖,4-
	else
		panelInfo.buttons  		= {}
		panelInfo.buttons[1]	= 1
	end

	if panelParams then			--其他参数
		panelInfo.showStyle = panelParams.showStyle
		panelInfo.param 	= panelParams.param
	end
	OpenActivityRightPanel( sysarg, activityType, activityId, panelInfo )
end

--[[
右侧面板内容变化
只发送变化的部分
buttons1:panelInfo.sts为1时显示的按钮
buttons2:panelInfo.sts为2时显示的按钮

contStyle:内容风格
1：  击杀BOSS：xx/xx
	 击杀小怪：xx/xx
2：  击杀BOSS1名称：0/1
	 击杀BOSS2名称：0/1
	 击杀BOSS3名称：0/1
	 击杀小怪：xx/xx
3:   击杀怪物:xx/xx
4:   剩余时间，此方法不使用4
5:	总共怪物波数：xx
	当前怪物波数：xx
	下次刷出：xx分钟 或者 即将刷出
	此方法不使用5
6：
	第一名玩家：%s
	第一名积分：%d
	我的积分：%d
	我的名次：%d
7:
总伤害:%d
攻击次数:%d
平均伤害:%d

9：排名(非来自于排行榜)

button--1：退出副本，2-单倍领奖，3-双倍领奖，4-查看排行榜，5-押镖寻路, 6-打开答题面板，7-放弃押镖，8-寻找活动NPC
	9-排名(非来自于排行榜)、10-选择BOSS（具体客户端处理）
]]
function ChangeCommonStylePanel( sysarg, sts, contStyle, bossConfig, buttons1, buttons2, panelParams )
	--print(" ChangeCommonStylePanel, contStyle="..contStyle)
	local panelInfo 	= {}
	panelInfo.contents 	= {}

	local contIdx = 0
	----额外参数处理
	if panelParams then	
		for i, content in ipairs( panelParams.contents or {} ) do 		--部分特色显示内容
			contIdx = i
			panelInfo.contents[contIdx] = content
		end
	end

	local allBoss, killBoss, allMon, killMon
	if contStyle == 1 then
		local fubenPtr 		= Actor.getFubenPrt(sysarg)
		local fubenHandle	= Fuben.getFubenHandle(fubenPtr)
		allBoss, killBoss, allMon, killMon = GetCommonBossMonsterNum6( fubenHandle, bossConfig.monsters )
		--print(" ChangeCommonStylePanel, allBoss="..allBoss..", killBoss="..killBoss..", allMon="..allMon..", killMon="..killMon)
		contIdx = contIdx + 1
		panelInfo.contents[contIdx] = string.format( Lang.ScriptTips.panelCont08, killBoss, allBoss)
		if allMon > 0 then
			contIdx = contIdx + 1
			panelInfo.contents[contIdx] = string.format( Lang.ScriptTips.panelCont07, killMon, allMon)
		end
	elseif contStyle == 2 then
		local fubenPtr 		= Actor.getFubenPrt(sysarg)
		local fubenHandle	= Fuben.getFubenHandle(fubenPtr)
		allBoss, killBoss, allMon, killMon = GetCommonBossMonsterNum6( fubenHandle, bossConfig.monsters )
		
		local contIdx = 0
		local bossNumTable = GetCommonBossNum( fubenHandle, bossConfig.monsters )
		for bossId, bossNum in pairs( bossNumTable or {} ) do
			contIdx = contIdx + 1
			local bossName = MonsterNameDeleteNumber( bossId )
			panelInfo.contents[contIdx] = string.format( Lang.ScriptTips.panelCont13, bossName, bossNum[1], bossNum[2])
		end
	elseif contStyle == 3 then
		local fubenPtr 		= Actor.getFubenPrt(sysarg)
		local fubenHandle	= Fuben.getFubenHandle(fubenPtr)
		allBoss, killBoss, allMon, killMon = GetCommonBossMonsterNum6( fubenHandle, bossConfig.monsters )
		panelInfo.contents[1] = string.format( Lang.ScriptTips.panelCont07, killBoss+killMon, allBoss+allMon)
	elseif contStyle == 6 then
		local actorId 	= Actor.getActorId( sysarg )
		local rankType 	= bossConfig.rankType or 0
		local actorName, actorPoint = GetCommonRankIdxNameAndValue( rankType, 1 )		--第一名
		local myIdx, myPoint = GetCommonRankActorIdxAndValue( rankType, actorId )		--本人
		if not actorName then
			actorName = Lang.ScriptTips.panelCont33
		end
		--print(" ChangeCommonStylePanel, myPoint="..myPoint..", myIdx="..myIdx)
		panelInfo.contents[1] = string.format( Lang.ScriptTips.panelCont31, actorName )
		panelInfo.contents[2] = string.format( Lang.ScriptTips.panelCont32, actorPoint )
		panelInfo.contents[3] = string.format( Lang.ScriptTips.panelCont16, myPoint )
		if myIdx > 0 then
			panelInfo.contents[4] = string.format( Lang.ScriptTips.panelCont20, myIdx )
		else
			panelInfo.contents[4] = Lang.ScriptTips.panelCont19
		end

		if not sts then
			sts = 1 			--进行中
		end
	elseif contStyle == 7 then
		local allHurt 	= bossConfig.allHurt			--总伤害
		local attackNum = bossConfig.attackNum			--攻击次数
		local avgHurt 	= 0
		if attackNum > 0 then
			avgHurt = math.floor( allHurt/attackNum )		--平均攻击
		end
		--print(" ChangeCommonStylePanel, allHurt="..allHurt..", attackNum="..attackNum..", avgHurt="..avgHurt)

		panelInfo.contents[1] = string.format( Lang.ScriptTips.panelCont34, allHurt )
		panelInfo.contents[2] = string.format( Lang.ScriptTips.panelCont35, attackNum )
		panelInfo.contents[3] = string.format( Lang.ScriptTips.panelCont36, avgHurt )

		if not sts then
			sts = 1 			--进行中
		end
	elseif contStyle == 9 then			--排名(非来自于排行榜)
		local myRankIdx = bossConfig.myRankIdx
		panelInfo.contents[1] = string.format( Lang.ScriptTips.panelCont20, myRankIdx )
	end

	if bossConfig.awards then
		panelInfo.awardTitle 	= Lang.ScriptTips.panelCont06  			--副本奖励Title
		panelInfo.awards 		= bossConfig.awards						--副本奖励
	end

	if sts then
		panelInfo.sts = sts
	else
		if killBoss + killMon >= allBoss + allMon then
			panelInfo.sts = 2  				--已通关
		else
			panelInfo.sts = 1  				--进行中
		end
	end

	if panelInfo.sts == 1 then
		panelInfo.buttons = buttons1
	else
		panelInfo.buttons = buttons2
	end

	ChangeActivityRightPanel( sysarg, panelInfo )
end




--[[
初始化右侧面板（特殊处理的功能使用，如魔幻迷城）
]]
function OpenCommonSpecialPanel( sysarg, activityType, activityId, panelInfo, bossConfig, buttons1, bossId, bossNumFunc )
	local fubenPtr 		= Actor.getFubenPrt(sysarg)
	local restTime 		= 0
	if activityType > 0 then
		restTime = Fuben.getFbTime( fubenPtr )						--副本剩余时间
	end
	
	panelInfo.sts 		= 1  										--进行中
	panelInfo.timeTitle = Lang.ScriptTips.panelCont01				--剩余时间
	panelInfo.restTime	= restTime

	panelInfo.contentTitle 	= Lang.ScriptTips.panelCont05  			--副本内容Title
	panelInfo.contents 		= {}

	if not bossNumFunc then
		bossNumFunc = GetCommonBossMonsterNum
	end

	local fubenPtr 		= Actor.getFubenPrt(sysarg)
	local fubenHandle	= Fuben.getFubenHandle(fubenPtr)
	local allBoss, killBoss, allMon, killMon = bossNumFunc( fubenHandle, bossConfig.monsters, bossConfig.monsterMaxNum, panelInfo )
	--print("OpenCommonBossPanelEx, allMon="..allMon..", killMon="..killMon)
	local contIdx = 0
	if allBoss > 0 then
		contIdx = contIdx + 1
		if bossId then
			local bossName = MonsterNameDeleteNumber(bossId)			--BOSS去掉后面数字
			panelInfo.contents[contIdx]	= string.format( Lang.ScriptTips.panelCont13, bossName, killBoss, allBoss)
		else
			panelInfo.contents[contIdx]	= string.format( Lang.ScriptTips.panelCont14, killBoss, allBoss)
		end
	end

	if allMon > 0 then
		contIdx = contIdx + 1
		panelInfo.contents[contIdx]	= string.format( Lang.ScriptTips.panelCont07, killMon, allMon)
	end

	if bossConfig.awards then
		panelInfo.awardTitle 	= Lang.ScriptTips.panelCont06  			--副本奖励Title
		panelInfo.awards 		= bossConfig.awards						--副本奖励
	end

	if not panelInfo.buttons then
		panelInfo.buttons  		= {}
		panelInfo.buttons[1]	= 1			--{1,2,3}		1-退出，2-（单倍）领奖，3-双倍领奖
	end

	OpenActivityRightPanel( sysarg, activityType, activityId, panelInfo )
end

--[[
右侧面板内容变化（特殊处理的功能使用，如魔幻迷城）
只发送变化的部分
]]
function ChangeCommonSpecialPanel( sysarg, bossConfig, buttons1, buttons2, bossId, bossNumFunc )
	--print(" ChangeCommonSpecialPanel, bossId="..bossId)
	if not bossNumFunc then
		bossNumFunc = GetCommonBossMonsterNum
	end
	local fubenPtr 		= Actor.getFubenPrt(sysarg)
	local fubenHandle	= Fuben.getFubenHandle(fubenPtr)
	local allBoss, killBoss, allMon, killMon = bossNumFunc( fubenHandle, bossConfig.monsters, bossConfig.monsterMaxNum )
	local panelInfo 	= {}
	if killBoss >= allBoss and killMon >= allMon then
		panelInfo.sts 	= 2				--已通关
	else
		panelInfo.sts 	= 1 			--进行中
	end
	panelInfo.contents 	= {}
	
	local contIdx = 0
	if allBoss > 0 then
		contIdx = contIdx + 1
		if bossId then
			local bossName = MonsterNameDeleteNumber(bossId)			--BOSS去掉后面数字
			panelInfo.contents[contIdx]	= string.format( Lang.ScriptTips.panelCont13, bossName, killBoss, allBoss)
		else
			panelInfo.contents[contIdx]	= string.format( Lang.ScriptTips.panelCont08, killBoss, allBoss)
		end
	end

	if allMon > 0 then
		contIdx = contIdx + 1
		panelInfo.contents[contIdx]	= string.format( Lang.ScriptTips.panelCont07, killMon, allMon)
	end

	if panelInfo.sts == 1 then
		panelInfo.buttons = buttons1
	else
		panelInfo.buttons = buttons2
	end

	ChangeActivityRightPanel( sysarg, panelInfo )
end


--[[
通用NPC显示面板
extConds：额外的条件
]]
function CommonNpcDialog( sysarg, cfg, dailyOpTimesId, dailyOpTimesParam, desc, functions, NpcDialogId, extConds )
	local conds 	= {}
	local condIdx	= 0
	if cfg and cfg.enterLevelLimit then
		local circleLimit 	= cfg.enterLevelLimit[1]
		local levelLimit 	= cfg.enterLevelLimit[2]
		local strColor 		= Lang.ScriptTips.Color_Greed
		if not Actor.checkActorLevel( sysarg, levelLimit, circleLimit ) then
			strColor = Lang.ScriptTips.Color_Red
		end
		local strCond = string.format( Lang.ScriptTips.LevelLimitCircleFormat, strColor, circleLimit, levelLimit )
		table.insert( conds, strCond )
	end

	if cfg and cfg.enterTimesLimit then
		local maxTimes   	= GetActorDailyMaxTimes( sysarg, dailyOpTimesId, dailyOpTimesParam )
		local doneTimes  	= GetActorDailyDoneTimes( sysarg, dailyOpTimesId, dailyOpTimesParam )
		local lastTimes  	= maxTimes - doneTimes
		if lastTimes < 0 then
			lastTimes = 0
		end
		local strColor = Lang.ScriptTips.Color_Greed
		if lastTimes <= 0 then
			strColor = Lang.ScriptTips.Color_Red
		end
		local strCond = string.format( Lang.ScriptTips.LastTimesFormat, strColor, lastTimes )
		table.insert( conds, strCond )
	end
	
	if cfg and cfg.recommandPower then
		local myPower = Actor.getIntProperty(sysarg, PROP_ACTOR_BATTLE_POWER)
		local strColor = Lang.ScriptTips.Color_Greed
		if cfg.recommandPower > myPower then
			strColor = Lang.ScriptTips.Color_Red
		end
		local strCond = string.format( Lang.ScriptTips.RecommandPowerFormat, strColor, cfg.recommandPower )
		table.insert( conds, strCond )
	end

	if cfg and cfg.openServerDay then
		local openDays = System.getDaysSinceOpenServer()
		local strColor = Lang.ScriptTips.Color_Greed
		if openDays < cfg.openServerDay then
			strColor = Lang.ScriptTips.Color_Red
		end

		local strCond = ""
		if cfg.openServerDay and openDays >= cfg.openServerDay then
			strCond = string.format( Lang.ScriptTips.LastOpenDaysLimitFormat2, strColor )
		else
			strCond = string.format( Lang.ScriptTips.LastOpenDaysLimitFormat1, strColor, cfg.openServerDay-openDays )
		end
		table.insert( conds, strCond )
	end


	if cfg and cfg.openOrCombServerDay then 			--开服前N1天或者合服前N2天   openOrCombServerDay = {7, 7}
		local strCond = ""
		if CheckOpenOrCombServerDayBegore( cfg.openOrCombServerDay ) then
			strCond = string.format( Lang.ScriptTips.OpenStatusFormat, Lang.ScriptTips.Color_Green, Lang.ScriptTips.COM0070 )
		else
			local openDays = System.getDaysSinceOpenServer()
			local combDays = System.getDaysSinceCombineServer()
			if cfg.openOrCombServerDay[1] > 0 and cfg.openOrCombServerDay[2] > 0 then 		--开服前N1天或合服前N2天
				strCond = string.format( Lang.ScriptTips.OpenOrCombDaysBeforeFormat, Lang.ScriptTips.Color_Red, cfg.openOrCombServerDay[1], cfg.openOrCombServerDay[2] )
			elseif cfg.openOrCombServerDay[2] <= 0 then
				 strCond = string.format( Lang.ScriptTips.OpenDaysBeforeFormat, Lang.ScriptTips.Color_Red, cfg.openOrCombServerDay[1] )
			elseif cfg.openOrCombServerDay[1] <= 0 then
				 strCond = string.format( Lang.ScriptTips.CombDaysBeforeFormat, Lang.ScriptTips.Color_Red, cfg.openOrCombServerDay[2] )
			end
		end
		table.insert( conds, strCond )
	end


	if cfg and cfg.enterDailyRechargeLimit then 		--每日充值要求
		local todayRechargeNum = Actor.getDailyChargeYuanBao( sysarg )
		local strColor = Lang.ScriptTips.Color_Greed
		if todayRechargeNum < cfg.enterDailyRechargeLimit then
			strColor = Lang.ScriptTips.Color_Red
		end

		if cfg.enterDailyRechargeLimit > 0 then
			local strCond = string.format( Lang.ScriptTips.DailyRechargeLimitFormat, strColor, cfg.enterDailyRechargeLimit )
			table.insert( conds, strCond )
		end
	end


	if cfg and cfg.enterVipLimit then
		local openDays 	= System.getDaysSinceOpenServer()
		local vipGrade 	= Actor.getVipGrade( sysarg )
		local needVip = 0
		if openDays <= cfg.enterVipLimit[1] then
			needVip = cfg.enterVipLimit[2] 		--开服N天内需要VIP等级
		else
			needVip = cfg.enterVipLimit[3] 		--开服N天后需要VIP等级
		end

		local strColor = Lang.ScriptTips.Color_Greed
		if vipGrade < needVip then
			strColor = Lang.ScriptTips.Color_Red
		end

		if needVip > 0 then
			local strCond = string.format( Lang.ScriptTips.VipLimitFormat, strColor, needVip )
			table.insert( conds, strCond )
		end
	end

	if cfg and cfg.enterConsume then
		local strColor 		= Lang.ScriptTips.Color_Greed
		local needItemId 	= cfg.enterConsume[1].id
		local needItemCount = cfg.enterConsume[1].count
		local hasItemNum = Actor.getItemCount( sysarg, needItemId )
		if hasItemNum < needItemCount then
			strColor = Lang.ScriptTips.Color_Red
		end
		local needItemname	= Item.getItemName( needItemId ) or ""
		local strCond = string.format( Lang.ScriptTips.NeedItemFormat, strColor, needItemname, needItemCount )
		table.insert( conds, strCond )
	end
	

	local strCond 	= ""
	local condNum	= #conds
	for condIdx=1, condNum do
		if condIdx < condNum then
			strCond  = strCond..conds[condIdx].."\n"
		else
			strCond  = strCond..conds[condIdx]
		end
	end

	--额外条件（显示）
	if extConds then
		for i, strCondExt in ipairs( extConds or {} ) do
			strCond  = strCond.."\n"..strCondExt
		end
	end

	local strBtnList = ""
	local funcNum = #functions
	for funcIdx=1, funcNum do
		local buttonName, functionName = functions[funcIdx][1], functions[funcIdx][2]
		local button = "{btn;0;"..buttonName..";%s;}"			--{按钮;样式;按钮名;函数名;描述}
		strBtnList = strBtnList .. string.format( button , functionName)
	end

	-----------------
	local strDesc = desc
	------------------

	-----------------
	local pack = DataPack.allocPacket(sysarg, LogicCmd.npcDialogSys.sysID, LogicCmd.npcDialogSys.sub.sNpcDlgData)
	DataPack.writeUint64(pack, Actor.getNpc(sysarg))
	DataPack.writeByte(pack, NpcDialogId)
	DataPack.writeString(pack, strCond)
	DataPack.writeString(pack, strDesc)
	DataPack.writeString(pack, strBtnList)
	DataPack.writeChar(pack, -1)
	DataPack.writeByte(pack, 0);
	DataPack.flush(pack)
end



--[[
初始化右侧面板
只有一个退出按钮
]]
function InitOnlyButtonPanel( sysarg, activityType, activityId, restTime, title )
	if restTime < 0 then
		restTime = 0
	end

	local panelInfo 	= {}
	panelInfo.sts 		= 1  										--进行中
	panelInfo.title 	= title
	panelInfo.timeTitle = Lang.ScriptTips.panelCont01			--剩余时间
	panelInfo.restTime	= restTime

	panelInfo.buttons   	= {}
	--panelInfo.buttons[1]	= 1		--1：退出副本，2-单倍领奖，3-双倍领奖，4-查看排行榜，5-押镖寻路, 6-打开答题面板，7-放弃押镖，8-寻找活动NPC
	panelInfo.showStyle		= 2  	--2-不显示面板，只显示门状的退出按钮和倒计时
	OpenActivityRightPanel( sysarg, activityType, activityId, panelInfo )
end

